﻿@using Pay.Core;
@{
    ViewBag.Title = "真实信息验证";
    Layout = "~/Views/Shared/_MallLayout.cshtml";
    var authModel = ViewBag.AuthModel as token_auth_model;
    string imgUrl = ViewBag.ImgUrl;
}
<body class="page-name page-namePass page-nameVerify">
    <div>
        <form id="authForm" name="authForm" enctype="multipart/form-data" method="post" action="@Url.Action("AuthenticationPost","Task")">
            <input type="hidden" id="user_name" name="user_name" value="@authModel.user_name" />
            <input type="hidden" id="type" name="type" value="@authModel.type" />
            <input type="hidden" id="card_no" name="card_no" value="@authModel.card_no" />
            <input type="hidden" id="card_img" name="card_img" value="@authModel.card_img" />
            <div>
                <div class="lt-block">
                    <div class="headTop no_id_card_img" style="@(!string.IsNullOrEmpty(authModel.card_img) ? "display:none" :"")">
                        <img src="~/Content/css/tokenmall/img/id1.jpg" alt="">
                    </div>
                    <div class="headImg has_id_card_img" style="@(!string.IsNullOrEmpty(authModel.card_img) ? "" : "display:none")">
                        <img id="preview" src="@(imgUrl + authModel.card_img)" alt="">
                        <label class="rpz" id="rpz">
                            重新拍照
                            <i class="icon-rpz"></i>
                            <input id="file_upload" type="file" class="pz" name="pz1" accept="image/*">
                        </label>
                    </div>
                </div>
                <div class="content">
                    <p class="col-gray fn28">
                        为验证是您本人进行操作，请您手持身份证正面拍照，
                        请保持五官清晰可见不可遮挡，身份证字迹清晰可见！
                    </p>
                    <div id="pz_div" class="btnBox" style="@(!string.IsNullOrEmpty(authModel.card_img) ? "display:none" :"")">
                        <label for="pz">
                            <input id="pz" name="pz" class="pz" type="file" accept="image/*">
                            <a id="pz_btn" href="#" class="ui-btn-buy">拍照</a>
                        </label>
                    </div>
                    <div id="finish_div" class="btnBox" style="@(!string.IsNullOrEmpty(authModel.card_img) ? "" : "display:none")">
                        <a href="javaScript:submitBankCard()" class="ui-btn-buy">完 成</a>
                    </div>
                </div>
            </div>
        </form>
    </div>
</body>

<script type="text/javascript">
    function submitBankCard() {
        $("#authForm").ajaxSubmit(function (result) {
            if (result.result_code == 1000) {
                layer.msg(result.result_msg);
                setTimeout(function () { window.location.href = '@Url.Action("List", "Task")';}, 1500);
            } else {
                layer.msg(result.result_msg);
            }
        });
    }


    //建立一個可存取到該file的url
    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(file);
        }
        else if (window.URL != undefined) {
            // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        }
        else if (window.webkitURL != undefined) {
            // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }
    $(function () {
        $(".pz").change(function () {
            if (this.files[0].size.toFixed(1) > 2 * 1024 * 1024) {
                $(this).val('');
                var hand_id_card_img = '@authModel.card_img';
                if (hand_id_card_img != undefined && hand_id_card_img != '') {
                    $("#preview").attr("src", '@(imgUrl + authModel.card_img)');
                    $(".has_id_card_img").css('display', '');
                    $(".no_id_card_img").css('display', 'none');
                } else {
                    $("#preview").attr("src", '');
                    $(".has_id_card_img").css('display', 'none');
                    $(".no_id_card_img").css('display', '');
                }
                layer.msg("请选择小于2M的图片");
                return false;
            }
            var objUrl = getObjectURL(this.files[0]);
            if (objUrl) {
                $("#preview").attr("src", objUrl);
                $(".has_id_card_img").css('display', '');
                $(".no_id_card_img").css('display', 'none');
                //$("#pz_btn").html("完成");
                $("#pz_div").css('display', 'none');
                $("#finish_div").css('display', '');
            }
        })
    })
</script>